import {
    getUserCompanyTreeList,
    getPierTaskPageList,
    getPierTaskByFid,
} from "@/api/request.js";

import actions from "@/actions";
import TableLyout from '@/components/commonPublic/tableLyout.vue'
import TableData from "@/components/commonPublic/el-table"; //主页面列表
import formJs from "./regexDetail.js"; //新增弹框配置项
import publicForm from "@/components/PCManage/fromCom.vue"; //弹框form
import messageBox from "@/components/public/messageBox"; //弹框

export default {
    name: "Monitoring",
    data() {
        return {
            names1: "Monitoring",
            projectsObj: [], //项目名
            tendersObj: [],
            falgId: null,
            editLoading: false,
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            btnObj: [{
                visible: true, // 是否展示出来
                title: "新增",
                name: this.yj_edit,
                order: 0
            }, {
                visible: true, // 是否展示出来
                title: "编辑",
                name: this.yj_edit,
                order: 1
            }, {
                visible: true, // 是否展示出来
                title: "提交",
                name: this.yj_submit,
                order: 2
            }, {
                visible: true, // 是否展示出来
                title: "删除",
                name: this.yj_delete,
                order: 3
            }, {
                visible: true, // 是否展示出来
                title: "查看",
                name: this.yj_edit,
                order: 4,
            }],
            // formData: {
            //     fId: "", // 工程信息fid  有值时表示修改  其余表示新增
            //     fCompanyid: "", // 施工单位id
            //     fCompanyname: "", // 施工单位名称
            //     fProjectid: "", // 项目id
            //     fProjectname: "", // 项目名称
            //     fEngineeringname: "", // 工程名称
            //     fEngineeringlocation: "", // 工程地点
            //     fEngineeringinfo: "", // 工程信息简述
            //     fDesignfile: "", // 设计资料文件id
            //     fPiercount: "", // 墩台数量
            //     fFoundationcount: "", // 基桩数量
            //     fRegistrantid: "", // 登记人id
            //     fRegistrantname: "", // 登记人名称
            //     fRegistdates: "", // 登记时间
            //     // 当前用户数据
            //     userId: "", // 当前登陆用户id
            //     userName: "", // 当前登陆用户名称
            //     recordfiles: [], //删除文件id集合--修改时传
            // },
            // 列表
            getList: {
                fprojectid: "",
                fCompanyid: null, //机构id
                fUserid: null, //当前登录用户id
                sublevel: "1", //查看下级  1是0否
                page: 1, //页码
                pageSize: 15, //每页条数
                keyWord: "", // 选择状态
                modelType: "0"
            },

            // getList: {
            //     modelType: "2", // 0代办 1已办  2查询页面
            //     fCompanyid: "", // 施工单位id
            //     fUserid: "", //当前登录用户id
            //     // 查询页面加上下面参数
            //     sublevel: "1", //查看下级  1是0否
            //     page: 1, //页码
            //     pageSize: 20, //每页条数
            // },



            activeIndex: "1",
            formData: {},


            loadingDialog: false,

            fCheckfileList: [],
            fScenepicfileList: [],
            fCheckfilesList: [],
            fHandlerpicfileList: [],
            fExceptionfileList: [],
            pierfoundationList: {},

            pdfUrl: "",
            fFileName: "",



            loading: false,
            tableData: [],

            queryCriteriaDatas: {}, //分页

        };
    },
    components: {
        TableLyout,
        TableData,
        publicForm,
        messageBox
    },
    created() {


    },
    mounted() {
        actions.onGlobalStateChange((state, prev) => {
            this.userInfo = prev.currentUser
            this.getList.fUserid = this.userInfo.id;
            this.getList.fCompanyid = this.userInfo.companyId;
        }, true);
        if (JSON.parse(sessionStorage.getItem("GxEmbedded_pcManage_getList"))) {
            var getListStorage = JSON.parse(sessionStorage.getItem("GxEmbedded_pcManage_getList"));
            this.getList = getListStorage
            if (getListStorage.fprojectid != "") {}
            this.yj_searchForm(this.getList)

        } else {
            this.yj_searchForm(this.getList)
        }

    },
    methods: {
        // 重置按钮
        reset(e) {
            this.getList = this.$options.data.call(this).getList
            this.getList.fprojectid = e
        },
        confirmMsg() {
            this.showMsgBox = false;
        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val;
        },
        yj_edit(num) {
            this.activeIndex = "1";
            // this.see = false;

            // this.formData = {
            //     // 任务表信息
            //     fId: "", // 检测任务信息表fid  有值时为修改  其余为新增
            //     fCompanyid: "", // 施工标段（单位）id  当前登录人
            //     fCompanyname: "", // 施工标段（单位）名称  当前登录人
            //     fProjectid: "", // 工程id   当前登录人
            //     fProjectname: "", // 工程名称  当前登录人
            //     fCheckcontent: "", // 检测项目
            //     fCheckfoundationcount: "", // 本次检测基桩数量
            //     fInspectiondates: "", // 报验日期
            //     fContactsandtel: "", //联系人和电话
            //     fCheckdates: "", // 检测日期
            //     fCheckerids: "", // 检测人员ids（字符串拼接","隔开）
            //     memberList: [],
            //     fCheckernames: "", // 检测人员names（字符串拼接","隔开）
            //     fIslastcheck: "否", // 是否最后一次检测 0-否  1-是
            //     fCheckfile: "", // 本次检测附件资料id
            //     // 子表信息
            //     pierfoundationList: [],
            //     // 当前用户信息
            //     userId: "", // 当前用户id
            //     userName: "", // 当前用户名称
            //     recordfiles: [
            //         //删除文件id集合--修改时传
            //     ],
            // };

            if (num == 0) {
                if (this.userInfo.companyId != "") {
                    this.$router.push({
                        path: "/pcManage/monitoringDetail",
                        query: {
                            // data: JSON.stringify(this.getList),
                            status: num
                        },
                    });
                } else {
                   
                    this.$message.warning({
                        content: "该用户无法新增",
                        duration: 1000
                    })

                }
            } else if (num == 1) {
                // 编辑
                if (this.currentRow != null) {
                    this.$router.push({
                        path: "/pcManage/monitoringDetail",
                        query: {
                            data: JSON.stringify(this.currentRow),

                            status: num
                        },
                    });

                } else {
                    this.$message.warning({
                        content: "请先选择需要编辑的数据",
                        duration: 1000
                    })
                }
            } else if (num == 4) {
                if (this.currentRow != null) {
                    this.$router.push({
                        path: "/pcManage/monitoringDetail",
                        query: {
                            data: JSON.stringify(this.currentRow),
                            status: num
                        },
                    });
                } else {
                    this.$message.warning({
                        content: "请先选择需要查看的数据",
                        duration: 1000
                    })
                }
            }
        },
    // 删除
    rowDelete(id) {
        if (id != "" && id != null) {
          this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              deletePierTaskByFid({ fId: id })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.reload();
                    this.$message.success("删除成功");
                  } else {
                    this.$message.error("删除失败", res.msg);
                    this.loading = false;
                    return false;
                  }
                })
                .catch(() => {
                  this.loading = false;
                  this.$message.error("删除接口调取失败");
                });
            })
            .catch(() => {
               this.$message("取消删除");
            });
        } else {
          return this.$message.error("请先选择需要删除的数据");
        }
      },
      SubmitText(id) {
        if (id != "" && id != null) {
          this.$confirm("是否继续提交?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              submitPierTask({
                fId: id,
              })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.reload();
                    this.$message.success("提交成功");
                  } else {
                    this.$message.error("提交失败", res.msg);
                    this.loading = false;
                    return false;
                  }
                })
                .catch(() => {
                  console.log("提交接口报错");
                  this.loading = false;
                });
            })
            .catch(() => {
             this.$message("取消提交");
            });
        } else {
          return this.$message.error("请先选择需要提交的数据");
        }
      },
        // 获取列表数据
        yj_searchForm(data) {
            this.loading = true;
            window.sessionStorage.setItem(
                "GxEmbedded_pcManage_getList",
                JSON.stringify(data)
            );
            var id;
            if(data.fCompanyid!=''){
              id=data.fCompanyid
            }else {
              id=data.fprojectid
            }
            var obj = {
                fprojectid: data.fprojectid,
                fCompanyid: id, //机构id
                fUserid: data.fUserid, //当前登录用户id
                sublevel: "1", //查看下级  1是0否
                page: data.page, //页码
                pageSize: data.pageSize, //每页条数
                modelType: "2"
                // keyWord: data.keyWord, // 选择状态
            }
            getPierTaskPageList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        var that = this;
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        that.queryCriteriaDatas = res.data.pageInfo; //分页信息


                    } else {
                        this.$message.warning({
                            content: "获取列表数据失败"+ res.msg,
                            duration: 1000
                        })
    
                        this.loading = false;
                        return false;
                    }
                })
                .catch(() => {
                    console.log("列表数据接口报错");
                    this.loading = false;
                });
        },

        // 点击工程名称
        openDialog(num, row) {
            this.see = true;
            if (num == "0") {
                this.fId = row.F_Id;
                this.editText();
            } else {
                this.textTitle = "查看基桩检测";
                this.dialogTableVisible = true;
                this.pierfoundationList = row;
                this.fScenepicfileList = row.picsfiles; // 现场照片
                this.fHandlerpicfileList = row.handlerfiles; // 处理照片
                this.fCheckfilesList = row.checkfiles; // 检测资料
                this.fExceptionfileList = row.exceptionfiles; // 异常资料
            }
        },
        // 查看
        editText() {
            this.activeIndex = "1";
            if (this.fId != null && this.fId != "") {
                this.dialogText = "查看";
                this.loadingDialogText = true;
                getPierTaskByFid({
                        fId: this.fId
                    })
                    .then((res) => {
                        if (res.errcode == 0) {
                            var that = this;
                            that.loadingDialogText = false;
                            that.dialogTableVisibleText = true;
                            that.formData = res.data.lrCheckPiertask;
                            that.timestamp = res.data.lrCheckPiertask.fCheckfile;
                            that.fCheckfileList = res.data.checkFile;
                            that.formData.recordfiles = [];
                        } else {
                            this.$message.warning({
                                content: "查看"+ res.msg,
                                duration: 1000
                            })
                            this.loadingDialogText = false;
                        }
                    })
                    .catch(() => {
                        console.log("查看接口报错");
                        this.loadingDialogText = false;
                    });
            } else {
                this.$message.warning({
                    content: "请先选择需要查看的数据",
                    duration: 1000
                })
            }
        },
        // 点击当前行
        getRowInfo(e, num) {
            this.fId = "";
            this.row = "";
            if (num == "0") {
                // 列表页当前行
                this.row = e;
                this.fId = e.F_Id;
            } else {
                //弹框内当前行
                this.row = e;
                this.fPiernumber = e.fId;
            }
        },
        // 展示文件
        openPdfs(v) {
            this.dialogPdf = true;
            this.pdfUrl = v.url;
            this.fFileName = v.fFileName;
        },



        //点击弹框内侧标题
        handleSelect(key) {
            this.activeIndex = key;
        },
    },
};